package com.gitee.swsk33.catservice.service.impl;

import com.gitee.swsk33.catentity.dataobject.Cat;
import com.gitee.swsk33.catentity.model.Result;
import com.gitee.swsk33.catservice.dao.CatDAO;
import com.gitee.swsk33.catservice.service.CatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CatServiceImpl implements CatService {

	@Autowired
	private CatDAO catDAO;

	@Override
	public Result<Cat> getById(int id) {
		Result<Cat> result = new Result<>();
		Cat getCat = catDAO.selectById(id);
		if (getCat == null) {
			result.setResultFailed("猫猫不存在！");
			return result;
		}
		result.setResultSuccess("查询成功！", getCat);
		return result;
	}

	@Override
	public Result<List<Cat>> getAll() {
		Result<List<Cat>> result = new Result<>();
		// selectList中传入null表示无条件，即查询全部数据
		result.setResultSuccess("查询完毕！", catDAO.selectList(null));
		return result;
	}

}